import 'package:example/models/todo_entity.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';

part 'todo_dao.dart';

class DatabaseHelper {
  static final DatabaseHelper _instance = DatabaseHelper._internal();

  factory DatabaseHelper() => _instance;

  DatabaseHelper._internal();

  static Database? _database;


  Future<Database> get database async {
    if (_database != null) return _database!;
    _database = await _initDB();
    return _database!;
  }

  Future<Database> _initDB() async {
    final path = join(await getDatabasesPath(), 'todo.db');
    return openDatabase(path, version: 1, onCreate: (db, version) async {
      await TodoDao().createTable(db);
    });
  }


}
